﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Model
{
    /// <summary>
    /// 观察者模式 基础类
    /// </summary>
    public abstract class ModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void Set<T>(ref T oldVal, T newVal, [CallerMemberName] string name = "")
        {
            if (!EqualityComparer<T>.Default.Equals(oldVal, newVal))
            {
                oldVal = newVal;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}
